<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/smoothness/jquery-ui-1.9.0.custom.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<script src="js/jquery-1.8.0.min.js" type="text/javascript"></script>										<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.9.0.custom.min.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->


<title>維護系統</title>

<script type="text/javascript">
$(document).ready(function() {
	
});
</script>

</head>
<body>

<table id="grid1"></table>
<div id="pager"></div>
<form id="kk">
<input id="AAAA" type="hidden" >
<input id="HHHH" type="hidden" >
</form>
<script type="text/javascript">

$("#grid1").jqGrid({
	url:'QueryBSS',
	datatype: "json",
	type: "post",
   	colNames:['系統ID', '系統名稱'],
   	colModel:[
   		{name:'AAAA',index:'AAAA',key:true,editable:true,editrules:{required:true}, width:70},
   		{name:'HHHH',index:'HHHH',editable:true,editrules:{required:true}, width:70}
   		//{name:'HHHH',index:'HHHH',editable:true,editrules:{custom:true,"custom_func":checkDuplicated,required:true}, width:70}
   	],
   	width:460,
   	rowNum:5,
   	loadonce:true,
   	rowList:[10,20,30],
   	pager: '#pager',
   	rownumbers: true,
   	viewrecords: true,	
   	/* ondblClickRow: function(AAAA){
		var su= $("#grid1").jqGrid("delRowData",AAAA);
   			if(su) alert("Succes. Write custom code to delete row from server==>"+AAAA); else alert("Allready deleted or not in list==>"+AAAA);
	}, */
	editurl: "ManipulateGrid",
    caption:"設定系統"
});

function checkDuplicated() {
	var sysId = $("#AAAA")[0].value;
	var ll = $("#grid1").jqGrid('getDataIDs');
	var isDuplicated = false;
	for(var i=0;i<ll.length;i++){
		if (ll[i] == sysId ) {
			isDuplicated = true;
		}
	}
	
	if (isDuplicated) {
		alert(sysId+"已經存在，系統ID不可重覆 !");
	} else {
		var sysName = $("#HHHH")[0].value;
		var dataAdd = {"AAAA":sysId,"HHHH":sysName};
		var _iCount = $("#grid1").jqGrid('getGridParam', 'records');
		$("#grid1").jqGrid('addRowData', _iCount+1,dataAdd);
		$("form#kk input#AAAA")[0].value = sysId;
	} 
	return [];
}

jQuery("#grid1").navGrid('#pager',{edit:true,add:true,del:true}
	,{	// edit
		onclickSubmit:function() {
			var sysId = $("#AAAA")[0].value;
			var sysName = $("#HHHH")[0].value;
			var dataAdd = {"AAAA":sysId,"HHHH":sysName};
			$("#grid1").jqGrid('setRowData', sysId,dataAdd);
		}
	}
	,{	// add
		onclickSubmit:function() {
			checkDuplicated();
		}
	}
);


</script>



</body>
</html>